package com.brtbeacon.wx.demo.mapview;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class MapAddActivity extends AppCompatActivity implements View.OnClickListener {

    private EditText editName;
    private EditText editURL;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_map_add);
        findViewById(R.id.btn_save).setOnClickListener(this);
        editName = findViewById(R.id.edit_name);
        editURL = findViewById(R.id.edit_url);
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_save: {
                Intent data = new Intent();

                String name = editName.getText().toString();
                String url = editURL.getText().toString();

                if (TextUtils.isEmpty(name)) {
                    Toast.makeText(this, "地图名称不能为空！", Toast.LENGTH_SHORT).show();
                    return;
                }

                if (TextUtils.isEmpty(url)) {
                    Toast.makeText(this, "地图链接不能为空！", Toast.LENGTH_SHORT).show();
                    return;
                }

                data.putExtra("name", name);
                data.putExtra("url", url);
                setResult(Activity.RESULT_OK, data);
                finish();
                break;
            }
        }
    }
}
